package cn.zifangsky.model;

import cn.zifangsky.utils.DateUtils;

import java.time.LocalDateTime;

public class AuthClientUser {
    private Integer id;

    private Integer authClientId;

    private Integer userId;

    private Integer authScopeId;

    private Long expiresIn;

    public Long getExpiresIn() {
        return expiresIn;
    }

    /**
     * 授权是否已经过期了
     * @return
     */
    public boolean isOverdue() {
        Long savedExpiresAt = this.getExpiresIn();
        //过期日期
        LocalDateTime expiresDateTime = DateUtils.ofEpochMillisecond(savedExpiresAt, null);
        //当前日期
        LocalDateTime nowDateTime = DateUtils.now();

        //如果过期时间超过了当前时间，那么Access Token已经失效，则返回错误提示
        return !expiresDateTime.isAfter(nowDateTime);
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAuthClientId() {
        return authClientId;
    }

    public void setAuthClientId(Integer authClientId) {
        this.authClientId = authClientId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Integer getAuthScopeId() {
        return authScopeId;
    }

    public void setAuthScopeId(Integer authScopeId) {
        this.authScopeId = authScopeId;
    }
}